import os,sys
from w1_ui import Ui_MainWindow
from PySide6.QtWidgets import QWidget,QApplication,QMainWindow, QTableWidgetItem, QLabel,QTableWidget
from PySide6.QtCore import Qt,QEvent,QMimeData
from PySide6.QtGui import QColor,QMouseEvent,QDrag
from tableclass import TeacherExchange,TeacherList
import pathlib
import sqlite3
from loger import Logger
from addTeacherClass import dialogAddTeacher
root=pathlib.Path(__file__).parent
# db=sqlite3.connect(str(root/"exam.db"))
# cur = db.cursor()
log = Logger('exam',StreamLevel='debug',FileLevel='info').logger
class mywin(QMainWindow):
    def __init__(self,parent=None):
        super().__init__(parent)
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)
        self.dialog=None
        db=sqlite3.connect(str(root/"exam.db"))
        self.cur=db.cursor()
#############################################################
        examRoomNum=21    #考场数
        examTeacherNum=2    #监考人数
        examNum=5   #考试科目数
#############################################################

        self.table=TeacherExchange(examRoomNum=examRoomNum,examTeacherNum=examTeacherNum,examNum=examNum)
        self.ui.verticalLayout_3.addWidget(self.table)


        self.table2=TeacherList(rows=60)
        # self.table2.forbidden_cells={(1,1),(1,2)}
        # self.table2.refreshBackground()
        
        self.ui.verticalLayout_2.addWidget(self.table2)


        self.table.setAcceptDrops(True)
        self.ui.initdb.triggered.connect(self.initdb)

        item=self.table.item(0,1)
        item.setText(f"七年级语文\n八年级语文\n九年级文\n2025-12-25\n07:30~10:00")
        # self.table.setItem(0,1,item)
        item.setTextAlignment(Qt.AlignCenter)
        
        self.setWindowTitle("监考表")
        self.ui.label.setText("1234")

       
    def initdb(self):
         log.debug("initdb")
         self.dialog=dialogAddTeacher(self)
         self.dialog.exec()
if __name__ =="__main__":
    app=QApplication()
    mywi=mywin()
    mywi.show()
    sys.exit(app.exec())